<template>
	<view class="content">
		<view class="header">
			<u-navbar 
			:border-bottom='false' 
			back-icon-color="#ffffff" 
			title-color="#ffffff" 
			:background="{background:'transparent'}" 
			back-text="" title="资金明细"></u-navbar>
			<view class="header_top">
				<view class="title">总计</view>
				<view class="usdt">{{sumnum}}USDT</view>
			</view>
		</view>
		<view class="tag">
			<u-tabs 
			height="60"
			:active-item-style='active' 
			bg-color="transparent" 
			:list="list" 
			bar-width="25%" 
			inactive-color="rgba(94, 106, 252,0.8)"
			active-color="#ffffff" 
			:is-scroll="false" 
			:current="current" 
			@change="change"></u-tabs>
		</view>
		<view class="cont">
			<scroll-view class="scroll-view_H" scroll-y="true" @scrolltolower="scrollBtm">
			    <view class="item" v-for="item in dataList" :key='item.id'>
			    	<view class="top">
			    		<view class="lf">{{item.reason}}</view>
			    		<view class="lr">{{item.number}}</view>
			    	</view>
			    	<view class="btm">
			    		<view class="lf">{{item.create_time}}</view>
			    		<view class="lr">{{item.bname=='usdt'?'USDT':'BST'}}</view>
			    	</view>
			    </view>
			    <view class="msg" :class="{order_null:dataList.length<=0}">
			    	<u-empty v-if="dataList.length<=0" text="暂无数据" mode="list"></u-empty>
			    	<u-loadmore :status="status" />
			    </view>
			</scroll-view>
			
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				active: {
					border: '1px solid #5e6afc',
					backgroundColor:'#5e6afc',
					borderRadius: '12rpx'
				},
				list: [
					{name: '合约'},
					{name: '盈亏'},
					{name: '矿机'},
					{name: '团队'},
				],
				current: 0,
				page:1,//当前页码
				list_rows:15,//每页数量
				total:0,//数据总量
				status: 'loadmore',
				dataList:[],
				usdt:0,
				usdtrmb:0,
				sumnum:0,//总计
			}
		},
		onReady() {
			
		},
		onLoad(e) {
			//console.log(e)
			this.getUserInfo()
			this.current = e.current || 0
			
			if(this.current == 0 || !this.current){

				this.get_shifang('购买合约')
			}
			if(this.current == 1){
				this.get_shifang('中奖获得')
			}
			if(this.current == 2){
				this.get_shifang('矿机释放获得')
			}
			if(this.current == 3){
				this.get_shifang('直推获得')
			}
		},
		onPullDownRefresh(){
			this.page = 1
			this.dataList=[]
			if(this.current == 0){
				this.get_shifang('购买合约')
			}
			if(this.current == 1){
				this.getcontractlog()
			}
			if(this.current == 2){
				this.get_shifang('矿机释放获得')
			}
			if(this.current == 3){
				this.get_shifang('直推获得')
			}
		},
		onReachBottom(){
			
		},
		methods: {
			scrollBtm(){
				if(Math.ceil(this.total/this.list_rows)>this.page){
					this.page = this.page+1
					if(this.current == 0){
						this.get_shifang('购买合约')
					}
					if(this.current == 1){
						this.getcontractlog()
					}
					if(this.current == 2){
						this.get_shifang('矿机释放获得')
					}
					if(this.current == 3){
						this.get_shifang('直推获得')
					}
				}else{
					
				}
			},
			//获取用户信息
			getUserInfo(){
				this.$http({
					url:this.$api.user_getinfo,
					method:'POST',
					success:res=>{
						//console.log('成功返回---------',res)
						this.usdt = res.data.usdt
						this.usdtrmb = res.data.usdtrmb
					}
				})
			},
			//释放
			get_shifang(e){
				this.status = 'loading'
				this.$http({
					url:this.$api.user_shifang,
					method:'POST',
					hideLoading:false,
					data:{page:this.page,list_rows:this.list_rows,reason:e},
					success:res=>{
						this.total = res.data.total
						if(Math.ceil(this.total/this.list_rows)<=this.page){
							this.status = 'nomore'
							
						}else{
							this.status = 'loadmore'
						}
						this.dataList = this.dataList.concat(res.data.data)
						this.sumnum = res.data.sumnum
					},
					fail:err=>{
						this.status = 'nomore'
						//console.log('失败返回------',err)
					},
					complete:e=>{
						uni.stopPullDownRefresh();
						if(!e.code){
							this.status = 'nomore'
						}
					}
				})
			},
			getcontractlog(){
				this.status = 'loading'
				this.$http({
					url:this.$api.contractlog_getAll,
					method:'POST',
					hideLoading:false,
					data:{
						page:this.page,
						list_rows:this.list_rows,
						status:2,
					},
					success:res=>{
						this.total = res.data.total
						if(Math.ceil(this.total/this.list_rows)<=this.page){
							this.status = 'nomore'
						}else{
							this.status = 'loadmore'
						}
						let d = res.data.data.map(item=>{
							return {reason:'',
							number:item.jieguoprice,
							create_time:item.create_time,
							bname:'usdt'
							}
							
						})
						this.dataList = this.dataList.concat(d)
						this.sumnum = res.data.sumnum
					},
					complete:e=>{
						uni.stopPullDownRefresh();
						if(!e.code){
							this.status = 'nomore'
						}
					}
				})
			},
			//切换tag
			change(index) {
				this.current = index;
				this.page = 1
				this.dataList=[]
				if(this.current == 0){
					this.get_shifang('购买合约')
				}
				if(this.current == 1){
					this.getcontractlog()
				}
				if(this.current == 2){
					this.get_shifang('矿机释放获得')
				}
				if(this.current == 3){
					this.get_shifang('直推获得')
				}
			},
			
		}
	}
</script>
<style lang="scss" scoped>
	.content{
		.header{
			background:url(../../static/zz.png)center/cover no-repeat;
			.header_top{
				text-align: center;
				padding: 30rpx 0 20rpx 0;
				box-shadow: 0 5rpx 5rpx rgba(62,9,149,1);
				color: #ffffff;
				.title{
					color:#999999;
				}
				.usdt{
					font-weight: 600;
					font-size: 18px;
				}
				
			}
			
		}
		.tag {
			margin: 52rpx 26rpx 0 26rpx;
			border: 1px solid rgba(94, 106, 252,0.5);
			border-radius: 15rpx;
			
		}
		.cont{
			margin: 16rpx 26rpx 0 26rpx;
			.item{
				padding: 22rpx 10rpx;
				border-bottom: 1px solid $border-bottom-color;
				>view{
					display: flex;
					justify-content: space-between;
				}
				.top{
					font-size:14px;
					font-weight: 600;
					color: #FFFFFF;
					letter-spacing: 1px;
				}
				.btm{
					font-size: 12px;
					color: #626cff;
					margin-top: 10rpx;
				}
			}
			.item:last-child{
				border-bottom: 0;
			}
		}
		.msg{
			padding: 20rpx;
		}
		.order_null{
			position: fixed;
			left: 0%;
			top: 50%;
			width: 100%;
		}
		.scroll-view_H{
			height: 70vh;
		}
	}
</style>